import { PetExploreConfigInfo } from "./info/PetExploreConfigInfo";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { SPetExploreInfo } from "../../../Message/Public/SPetExploreInfo";
type int = number;
//class PetExploreConfig
    
    export  class PetExploreConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (PetExploreConfig._instance != null) 
            {
                throw new Error(" PetExploreConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new PetExploreConfigInfo();
                loc1.id = loc2.id;
                loc1.level = loc2.level;
                loc1.area = loc2.area;
                loc1.name = loc2.name;
                loc1.map = loc2.map;
                loc1.startRing = loc2.startRing;
                loc1.bossDrops = loc2.bossDrops;
                loc1.dropItems = loc2.dropItems;
                loc1.bossIds = loc2.bossIds;
                loc1.factorCost = loc2.factorCost;
                loc1.x = loc2.x;
                loc1.y = loc2.y;
                loc1.parse();
                this._map[loc1.level] = loc1;
                var loc5;
                var loc6=((loc5 = this).rbNum + 1);
                loc5.rbNum = loc6;
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_pet_explore_config.json");
            this.write(loc1);
            return;
        }

        public getExploreConfigByArea(arg1: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (loc2.area != arg1) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getExploreConfigByLevel(arg1: int): PetExploreConfigInfo
        {
            return this._map[arg1];
        }

        public isAreaFirstRoadblock(arg1: PetExploreConfigInfo): Boolean
        {
            var loc1=false;
            var loc4=null;
            var loc2=this.getExploreConfigByArea(arg1.area);
            var loc3=(loc2[0] as PetExploreConfigInfo).level;
            var loc5=0;
            while (loc5 < loc2.length) 
            {
                if ((loc4 = loc2[loc5] as PetExploreConfigInfo).level < loc3) 
                {
                    loc3 = loc4.level;
                }
                ++loc5;
            }
            if (arg1.level == loc3) 
            {
                loc1 = true;
            }
            return loc1;
        }

        public getAreaFirstRoadblock(arg1: int): PetExploreConfigInfo
        {
            var loc1=false;
            var loc4=null;
            var loc2=this.getExploreConfigByArea(arg1);
            var loc3=(loc2[0] as PetExploreConfigInfo).level;
            var loc5=0;
            while (loc5 < loc2.length) 
            {
                if ((loc4 = loc2[loc5] as PetExploreConfigInfo).level < loc3) 
                {
                    loc3 = loc4.level;
                }
                ++loc5;
            }
            return this._map[loc3];
        }

        public getAreaIndexByLevel(arg1: int): int
        {
            var loc1=0;
            if (arg1 > this.rbNum) 
            {
                arg1 = this.rbNum;
            }
            var loc2=this.getExploreConfigByLevel(arg1);
            if (loc2) 
            {
                loc1 = loc2.area;
            }
            return loc1;
        }

        public getFactorCost(arg1: SPetExploreInfo): Array<any>
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            if (arg1) 
            {
                loc6 = arg1.currentLevel;
                while (loc6 <= arg1.autoMaxLevel) 
                {
                    if (loc3 = this.getExploreConfigByLevel(loc6)) 
                    {
                        loc4 = loc3.factorCost.split("#");
                        loc1 = loc1 + int(String(loc4[0]).split(",")[1]);
                        loc2 = loc2 + int(String(loc4[1]).split(",")[1]);
                    }
                    ++loc6;
                }
                return [loc1, loc2];
            }
            return [0, 0];
        }

        public static get instance(): PetExploreConfig
        {
            if (PetExploreConfig._instance == null) 
            {
                PetExploreConfig._instance = new PetExploreConfig();
            }
            return PetExploreConfig._instance;
        }

        public /* var */rbNum: int;

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: PetExploreConfig;
    }
